package com.jz.community.moduleexpress.express.adapter;


import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.basecomm.utils.BaseImageLoaderUtils;
import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.moduleexpress.R;
import com.jz.community.moduleexpress.express.info.ExpressInfoBean;

import java.util.List;

/**
 * Created by Andy Huang on 2018/2/28.
 *
 * @description:
 */

public class ExpressInfoListAdapter extends BaseQuickAdapter<ExpressInfoBean, BaseViewHolder> {

    private int statue;

    public ExpressInfoListAdapter(int layoutResId, @Nullable List<ExpressInfoBean> data) {
        super(layoutResId, data);
    }

    public ExpressInfoListAdapter(int layoutResId, @Nullable List<ExpressInfoBean> data, int statue) {
        super(layoutResId, data);
        this.statue = statue;
    }

    @Override
    protected void convert(BaseViewHolder helper, ExpressInfoBean item) {
        TextView text_status = helper.getView(R.id.text_status);
        TextView text_code_get = helper.getView(R.id.text_code_get);
        TextView text_express_name = helper.getView(R.id.text_express_name);
        TextView text_express_code = helper.getView(R.id.text_express_code);
        TextView text_express_time = helper.getView(R.id.text_express_time);
        TextView tv_express_commit_sign = helper.getView(R.id.tv_express_commit_sign);
        TextView tv_server_point_name = helper.getView(R.id.tv_server_point_name);
        ImageView imagr_icon = helper.getView(R.id.imagr_icon);
        ImageView image_have_sign = helper.getView(R.id.image_have_sign);
        BaseImageLoaderUtils.getInstance().loadDefaltImage(mContext,imagr_icon, item.getCompany().getIcon());
        if (!Preconditions.isNullOrEmpty(item.getCode())) {
            text_express_code.setVisibility(View.VISIBLE);
            text_express_code.setText("运单号: " + item.getCode());
        } else if (!Preconditions.isNullOrEmpty(item.getCode())) {
            text_express_code.setVisibility(View.VISIBLE);
            text_express_code.setText("运单号: 暂无");
        }
        text_express_time.setText(item.getAdd_time());
        text_express_name.setText(item.getCompany().getName());
        if (!Preconditions.isNullOrEmpty(item.getSpu_name())) {
            tv_server_point_name.setVisibility(View.VISIBLE);
            tv_server_point_name.setText("代收点: " + item.getSpu_name());
        } else if (!Preconditions.isNullOrEmpty(item.getSpu_name())) {
            tv_server_point_name.setVisibility(View.VISIBLE);
            tv_server_point_name.setText("代收点: 暂无地址");
        }
        if (statue == 0) {//0待取件
            text_status.setVisibility(View.GONE);
            text_code_get.setVisibility(View.VISIBLE);
            image_have_sign.setVisibility(View.GONE);
            text_code_get.setText(mContext.getString(R.string.sign_code, item.getSign_code()));
            tv_express_commit_sign.setVisibility(View.VISIBLE);

        } else if (statue == 1) {//2已签收
            tv_express_commit_sign.setVisibility(View.GONE);
            text_status.setVisibility(View.GONE);
            text_code_get.setVisibility(View.GONE);
            image_have_sign.setVisibility(View.VISIBLE);
        }
        helper.addOnClickListener(R.id.tv_express_commit_sign);
    }
}
